﻿using Microsoft.AspNetCore.Authorization;

namespace VisionCloud.Domain.Filters
{
    /// <summary>
    /// 授权策略模式枚举
    /// </summary>
    public enum PolicyEnum
    {
        /// <summary>
        /// 角色权限
        /// </summary>
        RequireRolePermission = 0,

        /// <summary>
        /// 需要faro和网络正常
        /// </summary>
        RequireFaroAndNet = 1,

        /// <summary>
        /// 不需要USBKey检查
        /// </summary>
        NoRequireUSBKey = 2,

        /// <summary>
        /// 检查用户设备的合法性（当前的用户是否在合法的设备上操作，验证MsDevice注册的UsbKeyNO,UserCode）
        /// </summary>
        RequireCheckUserDevice = 3,

        /// <summary>
        /// 需要管理员身份
        /// </summary>
        RequireAdmin = 4,

        /// <summary>
        /// 需要设备管理员
        /// </summary>
        RequireDeviceManager = 5,

        /// <summary>
        /// 需要公司管理员和测量管理员
        /// </summary>
        RequireCompanyManager = 6
    }

    /// <summary>
    /// 自定义授权特性
    /// </summary>
    public class ApiAuthorizeAttribute : AuthorizeAttribute
    {
        /// <summary>
        /// 设置策略属性
        /// </summary>
        /// <param name="policyEnum"></param>
        public ApiAuthorizeAttribute(PolicyEnum policyEnum)
        {
            Policy = policyEnum.ToString();
        }

        /// <summary>
        /// 设置策略属性
        /// </summary>
        /// <param name="name"></param>
        public ApiAuthorizeAttribute(string name)
        {
            Policy = name;
        }
    }
}